package com.itheima.admin.controller;

import com.itheima.PageVo;
import com.itheima.Result;
import com.itheima.admin.dto.PageDto;
import com.itheima.admin.dto.RoleDto;
import com.itheima.admin.pojo.Role;
import com.itheima.admin.service.IRoleService;
import com.itheima.admin.vo.RoleVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/role")
public class  RoleController {
    @Autowired
    private IRoleService roleService;
    @PostMapping("/list")
    public PageVo<RoleVo> queryByPage(@RequestBody PageDto pageDto){
        return roleService.queryByPage(pageDto);
    }

    @GetMapping("/all")
    public List<RoleVo> queryAll(){
          return roleService.queryAll();
    }

    @PostMapping("/add")
    public Result addRole(@RequestBody RoleDto roleDto){
       boolean result= roleService.addRole(roleDto);
        return new Result(result,result?"新增用户成功":"新增用户失败",null);
    }
    @ApiOperation("删除失败")
    @DeleteMapping("/{id}")
    public Result deleteRole(@PathVariable("id") String id){

        boolean result= roleService.deleteRole(id);
        return new Result(result,result?"新增用户成功":"新增用户失败",null);
    }
@ApiOperation("角色授权")
    @PostMapping("/auth")
    public Result roleAuth(Map map){
       boolean result= roleService.roleAuth(map);
        return new Result(result,result?"角色授权成功":"角色授权失败",null);
    }
}
